import {createSlice,createAsyncThunk} from "@reduxjs/toolkit";
import {getHomeGoodPriceData} from "@/services";

export const fetchHomeDataAction = createAsyncThunk("fetchdata", async ()=>{
    const res = await getHomeGoodPriceData()
    return res
    // getHomeGoodPriceData().then(res => {
    //     console.log(res)
    // })
})

const homeSlice = createSlice({
    name:"home",
    initialState:{
        goodsPriceInfo:{}
    },
    reducers:{
        changeGoodsPriceInfoAction(state,{payload}){
            state.goodsPriceInfo = payload
        }
    },
    // extraReducers:{
        // [fetchHomeDataAction.fulfilled](state,{payload}){
        //     console.log(payload)
        //     state.goodsPriceInfo = payload
        // }
    // }
    extraReducers:(builder)=>{
        builder.addCase(fetchHomeDataAction.fulfilled,(state, {payload}) =>{

            console.log(payload)
            state.goodsPriceInfo = payload
        })
    }
})

export const  {changeGoodsPriceInfoAction } = homeSlice.actions


export default homeSlice.reducer
